package day0427.com;/*
 * @创建者：黄苟苟
 * @创建时间：2021/4/27   10:53
 * @Description描述
 **/

public class ArithmeticExceptionTest {
    public int devide(int x,int y) {

        try {
            int reult = x / y;
            return reult;

        } catch (java.lang.ArithmeticException e) {
            e.printStackTrace();//将异常打印到控制台
            System.out.print(e.getClass().getName() + ":");//获取异常名称
            System.out.println(e.getMessage());//异常描述
            StackTraceElement[] elements = e.getStackTrace();//异常跟踪信息
            for (StackTraceElement element : elements) {
                System.out.print("  at " + element.getClassName());//获取地址
                System.out.print("." + element.getMethodName());//获取方法
                System.out.print("(" + element.getFileName() + ".");//获取方法区域
                System.out.println(element.getLineNumber() + ")");//获取行数
            }

        } catch (Exception ee) {
            ee.printStackTrace();
            System.out.println(ee.getMessage());
            System.out.println(ee.getClass().getName());
        }
return 0;
    }
    public static String getExceptionMessage(Exception e){
        String retStr="";
        retStr=retStr+e.getClass().getName()+":"+e.getMessage()+"\n";
        StackTraceElement[] elements=e.getStackTrace();
        for (StackTraceElement element : elements) {

        }
        return null;
    }

    public static void main(String[] args) {
        ArithmeticExceptionTest mathTest =new ArithmeticExceptionTest();
        int reult=mathTest.devide(9,0);

    }
}
